<template>
  <el-dialog
    top="5vh"
    width="55%"
    title="检验"
    append-to-body
    v-if="visible"
    :modal-append-to-body="true"
    :close-on-click-modal="false"
    :visible.sync="visible"
    @close="handleInspectionReset"
  >
    <div class="dialog-content">
      <div class="wrapper-btn">
        <avue-form ref="basicInfoForm" v-if="visible" v-model="form" :option="basicInfoOption"></avue-form>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" size="small" @click="submitInspection()">提交检验</el-button>
      <el-button size="small" icon="el-icon-delete" @click="handleInspectionReset">取消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { handleReport } from '@/api/quality/incomingMaterialsToBeInspected';

export default {
  name: 'handleIqcInspection',
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {},
      basicInfoOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 100,
        column: [
          {
            label: '检验结果',
            prop: 'examineResult',
            span: 8,
            type: 'select',
            dicData: [
              {
                label: 'OK',
                value: 'OK'
              },
              {
                label: 'NG',
                value: 'NG'
              }
            ]
          },
          {
            label: '检验数量',
            prop: 'examineQuantity',
            span: 8,
            minRows: 0,
            type: 'number'
          },
          {
            label: '检验合格数量',
            prop: 'examineOkQuantity',
            span: 8,
            minRows: 0,
            type: 'number'
          },
          {
            label: '送检数量',
            prop: 'sendExamineQuantity',
            disabled: true,
            span: 8,
            minRows: 0,
            type: 'number'
          },
          {
            label: '备注',
            prop: 'remark',
            type: 'textarea',
            span: 24
          }
        ]
      }
    };
  },
  methods: {
    setForm(data) {
      this.$set(this.form, 'sendExamineQuantity', data.sendExamineQuantity);
      this.$set(this.form, 'id', data.id);
    },
    handleInspectionReset() {
      this.form = {};
      this.$refs.basicInfoForm.resetForm();
      this.$emit('update:visible', false);
      this.$emit('closeDialog');
    },
    //提交检验
    submitInspection() {
      let params = [
        {
          id: this.form.id,
          examineResult: this.form.examineResult,
          examineQuantity: this.form.examineQuantity,
          examineOkQuantity: this.form.examineOkQuantity,
          sendExamineQuantity: this.form.sendExamineQuantity,
          examineReport: '',
          examineDescription: '',
          remark: this.form.remark
        }
      ];
      handleReport(params).then((res) => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.form = {};
        this.$emit('sumbit');
        this.$refs.basicInfoForm.resetForm();
      });
    }
  }
};
</script>
